package interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class FirstInterceptor implements HandlerInterceptor {
    // 拦截器的请求拦截方式，会在 Handler 执行之前执行
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("FirstInterceptor的preHandle方法被执行了");
        // true代表放行 false代表拦截
        return true;
    }
    // 会在 Handler 执行之后，视图解析器之前执行
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("FirstInterceptor的postHandle方法被执行了");
    }

    // 会在视图解析器之后，渲染之前执行 一般用于垃圾的回收清扫
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("FirstInterceptor的afterCompletion方法被执行了");
    }
}
